package com.travel.server.manager.impl.command.user;

import com.travel.server.manager.dto.request.user.QueryDepartmentDetailRequest;
import com.travel.server.manager.dto.response.user.QueryDepartmentDetailResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.DepartmentDal;
import com.travel.server.manager.model.DepartmentInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: LiZhenhui
 * @Date: 2018/11/20 14:22
 * @Desc:
 */
@Component
public class QueryDepartmentDetailCommand extends AbstractCommand<QueryDepartmentDetailRequest, QueryDepartmentDetailResponse> {

    @Autowired
    private DepartmentDal departmentDal;

    @Override
    protected void checkInput(QueryDepartmentDetailRequest request) {
        if(request.getId() == null){
            throwInvalidParam();
        }
    }

    @Override
    public QueryDepartmentDetailResponse handle(QueryDepartmentDetailRequest request) {
        checkInput(request);

        QueryDepartmentDetailResponse response = new QueryDepartmentDetailResponse();

        DepartmentInfo departmentInfo = departmentDal.selectById(request.getId());
        response.setName(departmentInfo.getDepartmentName());
        response.setDescribe(departmentInfo.getDepartmentDescribe());

        return response;
    }
}
